// Fill out your copyright notice in the Description page of Project Settings.


#include "Common/Libraries/CommonLibrary.h"
#include "Blueprint/UserWidget.h"
#include "Blueprint/WidgetBlueprintGeneratedClass.h"
#include "Animation/WidgetAnimation.h"
#include "MovieScene.h"

void UCommonLibrary::ShowMessageOnScreen(const FString& Message)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Green, Message);
	}
}

UWidgetAnimation* UCommonLibrary::GetAnimInstance(TSubclassOf<UUserWidget> LocWidgetClass, const FText AnimName)
{
	UWidgetBlueprintGeneratedClass* WidgetClass = Cast<UWidgetBlueprintGeneratedClass>(LocWidgetClass.Get());
	if (!WidgetClass)
	{
		DEBUG_MESSAGE("WidgetClass Cast Fail");
		return nullptr;
	}
	for (auto Iter2 = WidgetClass->Animations.CreateIterator(); Iter2; ++Iter2)
	{
		UWidgetAnimation* Anim = *Iter2;
		if (Anim->GetMovieScene()->GetFName().IsEqual(*AnimName.ToString()))
		{
			return Anim;
		}
	}
	DEBUG_MESSAGE("Didn't Find Slid Animation");
	return nullptr;
}

//UWidgetAnimation* USingleMarkerWidget::GetAnim(FText AnimName) {
//	UWidgetBlueprintGeneratedClass* WidgetClass = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
//	if (!WidgetClass) {
//		DEBUG_MESSAGE("WidgetClass Cast Fail");
//		return nullptr;
//	}
//	for (TArray< UWidgetAnimation* >::TIterator Iter2 = WidgetClass->Animations.CreateIterator(); Iter2; ++Iter2)
//	{
//		UWidgetAnimation* Anim = *Iter2;
//		if (Anim->GetDisplayName().EqualToCaseIgnored(AnimName)) {
//			return Anim;
//		}
//	}
//	DEBUG_MESSAGE("Didn't Find Slid Animation");
//	return nullptr;
//}
